﻿using System;
using DbConnect.Sql;
using DbConnect;

namespace DnDEngine.Class
{
    public class Status
    {

        #region "Private attributes"

        #endregion

        #region "Properties"

        public int ID
        {
            get;
            set;
        }

        public String Lib
        {
            get;
            set;
        }

        #endregion

        #region "Events"

        #endregion

        #region "Public functions"

        public Status(int IDStatus)
        {

            try
            {
                Logger.Log.TraceAction("Status.Constructor", "");
                ID = IDStatus;
                Load();
            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("Status.Constructor", ex);
            }
            finally
            {
            }
        }

        private void Load()
        {


            try
            {
                Logger.Log.TraceAction("Status.Load", "");
                var data = new DbConnect.DataAccess();
                var req = SqlStatus.Select;
                data.AddParam(ParamStatus.ID, ID);

                var table = data.SelectWithParam(req);

                if (table != null && table.Rows.Count > 0)
                {
                    Lib = table.Rows[0].GetStringValue("StatusLib");
                }

            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("Status.Load", ex);

            }
            finally
            {
            }
        }

        private void Insert()
        {

            try
            {
                Logger.Log.TraceAction("Status.Insert", "");
                var data = new DbConnect.DataAccess();
                data.AddParam(ParamStatus.Lib, Lib);

                var req = SqlStatus.InsertInto;

                data.Insert(req);

                ID = data.GetLastIDInserted(SqlDownload.TableName);
            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("Status.Insert", ex);
            }
            finally
            {
            }
        }

        private void Update()
        {

            try
            {
                Logger.Log.TraceAction("Status.Update", "");
                var data = new DbConnect.DataAccess();
                data.AddParam(ParamStatus.Lib, Lib);
                data.AddParam(ParamStatus.ID, ID);

                var req = SqlStatus.Update;

                data.Update(req);
            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("Status.Update", ex);
            }
            finally
            {
            }
        }

        private void Delete()
        {

            try
            {
                Logger.Log.TraceAction("Status.Delete", "");
                var data = new DbConnect.DataAccess();

                data.AddParam(ParamStatus.ID, ID);

                var req = SqlStatus.Delete;

                data.Delete(req);
            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("Status.Delete", ex);
            }
            finally
            {
            }
        }


        #endregion

        #region "Private functions"

        #endregion


    }
}
